// pages/zaixiao/zaixiao.js
let that = null // 页面this指针变量
let db = wx.cloud.database();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        latitude: 40.003785,
        longitude: 116.34448,
        scale: 19,
        enablesatellite: false,
        markers: [],
        isShow: true, //显示内容
        showPlants: true, //是否显示植物图标（大于20的地图缩放级别才显示）
        name:'',
        number:0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that = this
        // console.log(options)
        let id = options.id
        let markPic = options.markPic
        let name = options.name
        that.setData({
            name:name,
           
        })
        // id = '63605076624bb25103fb9e0645cdf1f6'
        // console.log("id", id);
        // console.log("iconPath", markPic);
        //查询植物标注，获取该植物的标注数据
        db.collection("plantsMarks").where({
            plant: id
        }).get().then(res => {
            that.setData({
                markers: []
            })

            // console.log(res)
            if (res.data.length > 0) {
                let newMarkers = []
                res.data.forEach((item, index) => {
                    newMarkers.push({
                        id: index,
                        latitude: item.latitude,
                        longitude: item.longitude,
                        iconPath: markPic,
                        width: '20',
                        height: '20'
                    })
                })
                // console.log(newMarkers);
                that.setData({
                    markers: newMarkers,
                    number:newMarkers.length
                })
            }

        }).catch(res => {
            console.log(res)
        })


    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },



})